package com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.authoritymanagement.core.domain.aggregatemodel.PinyinCount;
import com.smedi.ismedi.authoritymanagement.core.domain.repository.PinyinCountRepository;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.model.PinyinCountEntity;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.mybatis.mapper.PinyinCountMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * @Author: xulinjun
 * @Date: 2021-6-8 14:02
 */
@Slf4j
@Repository
@AllArgsConstructor
public class PinyinCountRepositoryImpl extends ServiceImpl<PinyinCountMapper, PinyinCountEntity> implements PinyinCountRepository, IService<PinyinCountEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public void doInsert(PinyinCount data) {
        PinyinCountEntity pinyinCountEntity = dozerUtil.convertor(data, PinyinCountEntity.class);
        this.getBaseMapper().insert(pinyinCountEntity);
    }

    @Override
    public void doUpdate(PinyinCount data) {
        PinyinCountEntity pinyinCountEntity = dozerUtil.convertor(data, PinyinCountEntity.class);
        this.getBaseMapper().updateById(pinyinCountEntity);
    }

    @Override
    public int selectMaxCountByPinyin(String pinyin) {
        return this.selectMaxCountByPinyin(pinyin);
    }

    @Override
    public PinyinCount selectByPinyin(String pinyin) {
        QueryWrapper<PinyinCountEntity> wrapper = new QueryWrapper();
        wrapper.eq("pinyin", pinyin);
        PinyinCountEntity pinyinCountEntity = this.getBaseMapper().selectOne(wrapper);
        return dozerUtil.convertor(pinyinCountEntity, PinyinCount.class);
    }
}
